<template>
  <div class="order-list">
    <order-header title="订单列表">
      <template v-slot:tip>
        <span>请谨防钓鱼链接或诈骗电话，了解更多></span>
      </template>
    </order-header>
    <div class="container">
      <loading v-if="loading"></loading>
      <div class="wrap" v-for="(item, index) in list" :key="index">
        <div class="header">
          <div class="title">
            {{ item.createTime }}
            <span>|</span>
            {{ item.receiverName }}
            <span>|</span>
            订单号：{{ item.orderNo }}
            <span>|</span>
            {{ item.paymentTypeDesc }}
          </div>
          <div class="pay">
            应付金额：
            <span>{{ item.payment }}</span>
            元
          </div>
        </div>
        <div class="order-content clearfix">
          <div class="good-box fl">
            <div
              class="good-list"
              v-for="(val, i) in item.orderItemVoList"
              :key="i"
            >
              <div class="good-img">
                <img v-lazy="val.productImage" alt />
              </div>
              <div class="good-name">
                <div class="p-name">{{ val.productName }}</div>
                <div class="p-money" @click="goPay()">
                  {{ val.totalPrice + "X" + val.quantity }}元
                </div>
              </div>
            </div>
          </div>
          <div class="good-state fr" v-if="item.status == 20">
            <a href="javascript:;">{{ item.statusDesc }}</a>
          </div>
          <div class="good-state fr" else>
            <a href="javascript:;" @click="goPay(item.orderNo)">{{
              item.statusDesc
            }}</a>
          </div>
        </div>
      </div>
      <el-pagination
        class="pagination"
        background
        layout="prev, pager, next"
        :pageSize="pageSize"
        :total="total"
        @current-change="handelchange"
      >
      </el-pagination>
      <!-- <div
        class="scroll-more"
        v-infinite-scroll="scrollMore"
        infinite-scroll-disabled="busy"
        infinite-scroll-distance="410"
      >
        <img
          src="/imgs/loading-svg/loading-spinning-bubbles.svg"
          alt=""
          v-show="loading"
        />
      </div> -->
      <no-data v-if="!loading && list.length == 0"></no-data>
    </div>
  </div>
</template>

<script>
import OrderHeader from "../components/OderHeader";
import Loading from "../components/Loading";
import NoData from "../components/NoData";
import { Pagination } from "element-ui";
import infiniteScroll from "vue-infinite-scroll";
export default {
  name: "order-list",
  components: {
    OrderHeader,
    Loading,
    NoData,
    [Pagination.name]: Pagination,
  },
  directives: { infiniteScroll },
  data() {
    return {
      list: [],
      loading: true,
      pageSize: 10,
      pageNum: 1,
      total: 0,
      busy: false,
    };
  },
  mounted() {
    this.getOrderList();
  },
  methods: {
    // getList() {
    //   // 请求开始之前设置显示
    //   this.busy = true;
    //   this.axios
    //     .get("/orders", {
    //       params: {
    //         pageNum: this.pageNum,
    //       },
    //     })
    //     .then((res) => {
    //       this.list = res.list.concat(res.list); //把每次的更新的数据都累计在一起。
    //       //请求结束后设置不显示
    //       this.busy = true;
    //       if (res.hasNextPage) {
    //         this.busy = false;
    //       } else {
    //         this.busy = true;
    //       }
    //     });
    // },
    getOrderList() {
      this.axios
        .get("/orders", {
          params: {
            pageNum: this.pageNum,
          },
        })
        .then((res) => {
          this.loading = false;
          this.list = res.list;
          this.total = res.total;
        })
        .catch(() => {
          this.loading = false;
        });
    },
    goPay(orderNo) {
      this.$router.push({
        path: "/drder/list",
        query: {
          orderNo,
        },
      });
    },
    handelchange(pageNum) {
      this.pageNum = pageNum; //拿到当前的页数，
      this.getOrderList();
    },
    // scrollMore() {
    //   this.busy = true;
    //   setTimeout(() => {
    //     //得到新的缓存数据
    //     this.pageNum++;
    //     this.getList();
    //   }, 500);
    // },
  },
};
</script>

<style lang="scss">
@import "../assets/scss/config.scss";
@import "../assets/scss/mixin.scss";
.order-list {
  background-color: #f5f5f5;
  padding-bottom: 50px;
  .wrap {
    margin-top: 30px;
    border: 1px solid #d7d7d7;
    .header {
      background-color: #fffaf7;
      font-size: 16px;
      color: #666666;
      display: flex;
      justify-content: space-between;
      height: 80px;
      line-height: 80px;
      padding: 0 50px;
      .title {
        span {
          padding: 0 10px;
        }
      }
      .pay {
        span {
          color: #333333;
          font-size: 26px;
        }
      }
    }
    .order-content {
      background-color: #ffffff;
      padding: 0 43px;
      .good-box {
        width: 88%;
        .good-list {
          display: flex;
          align-items: center;
          height: 145px;
          .good-img {
            width: 112px;
            img {
              width: 100%;
            }
          }
          .good-name {
            font-size: 20px;
            color: $colorB;
          }
        }
      }
      .good-state {
        height: 145px;
        line-height: 145px;
        font-size: 20px;
        color: $colorA;
        a {
          color: $colorA;
        }
      }
    }
  }
  .pagination {
    text-align: right;
    margin-top: 30px;
  }
  .el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color: $colorA;
    color: #fff;
  }
  // .scroll-more {
  //   text-align: center;
  // }
}
</style>
